<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of verificateurDate
 * Vérifie la validité d'une date au format suivant : dd/mm/aaaa
 *
 * @author Miage
 */
class verificateurDate {

    private $date;
    private $dateBDD = null;

    public function __construct($_date) {
        $this->date = $_date;
    }

    public function estValide($_dateSup) {
        if (strlen($this->date) == 10) {
            $date = explode("/", $this->date);
            if (checkdate($date[1], $date[0], $date[2])) {
                $timestamp = mktime(0, 0, 0, $date[1], $date[0], $date[2]);
                //Si la date entrée par l'utilsateur est inférieur à la date actuelle
                if (!$_dateSup) {
                    if ($timestamp < time()) {
                        $timestamp = mktime(0, 0, 0, $date[1], $date[0], $date[2]);
                        $this->dateBDD = date('Y-m-d', $timestamp);
                        return true;
                    }
                } else {
                    if ($timestamp >= time()) {
                        $timestamp = mktime(0, 0, 0, $date[1], $date[0], $date[2]);
                        $this->dateBDD = date('Y-m-d', $timestamp);
                        return true;
                    }
                }
            }
        }
        return false;
    }

    /**
     * Retourne la date pouvant être insérée en base
     */
    public function getDateCompatibleBDD() {
        return $this->dateBDD;
    }

}

?>
